package com.zk.curator;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

/**
 * ClassName: Test
 * Desc:
 * Date： 2016/12/6
 * Created：shaom
 */
public class Test {

    public static void main(String[] args) throws Exception {
//        test1();
        test2();

    }

    private static void test1() throws IOException, ClassNotFoundException {
        Apple apple = Apple.getApple();
        Apple apple2 = Apple.getApple();
        System.out.println(apple == apple2);

        ObjectOutputStream oo = new ObjectOutputStream(new FileOutputStream(new File("E:/Person.txt")));
        oo.writeObject(apple);
        oo.close();

        ObjectInputStream ois = new ObjectInputStream(new FileInputStream(new File("E:/Person.txt")));
        Apple apple3 = (Apple) ois.readObject();
        ois.close();

        System.out.println(apple == apple3);
    }


    private static void test2() throws IOException, ClassNotFoundException {
        Apple2 apple = Apple2.getApple();
        Apple2 apple2 = Apple2.getApple();
        System.out.println(apple == apple2);

        ObjectOutputStream oo = new ObjectOutputStream(new FileOutputStream(new File("E:/Person.txt")));
        oo.writeObject(apple);
        oo.close();

        ObjectInputStream ois = new ObjectInputStream(new FileInputStream(new File("E:/Person.txt")));
        Apple2 apple3 = (Apple2) ois.readObject();
        ois.close();

        System.out.println(apple == apple3);
    }

}
